package jf.jcube;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import jf.jcube.data.DataLoader;
import jf.jcube.model.Dimension;
import jf.jcube.spec.Function;

public class JCube {

    private DataLoader dataProvider;

    private List<Dimension> rowDim;

    private List<Function> dataFns;

    public JCube(DataLoader provider) {
        this.dataProvider = provider;
    }

    public void setRowDimension(List<String> names) {
        rowDim = subsetOfDimension(names);
    }

    public void setDataFuntions(List<Function> dataFns) {
        this.dataFns = dataFns;
    }

    private List<Dimension> subsetOfDimension(List<String> names) {
        List<Dimension> dimensions = dataProvider.getDimensions();
        Map<String, Dimension> map = new HashMap<String, Dimension>();
        for (Dimension dimension : dimensions) {
            map.put(dimension.getName(), dimension);
        }
        List<Dimension> dims = new ArrayList<Dimension>();
        for (String name : names) {
            Dimension dimension = map.get(name);
            if (dimension == null) {
                throw new IllegalArgumentException("invalid dimension name '" + name + "'");
            }
            dims.add(dimension);
        }
        
        return dims;
    }
}
